//
// Created by Zhangwj on 2023/9/27.
//

#include <stdexcept>
#include "NumberNode.h"

std::unique_ptr<NumberNode> NumberNode::NumberParser(Parser &parser) {
    //Number → IntConst
    std::unique_ptr<NumberNode> numberNode = std::make_unique<NumberNode>();
    if (parser.getLexType(0) == LexType::INTCON) {
        try {
            numberNode->IntConst = std::stoul(parser.getString(0));
        } catch (const std::invalid_argument &e) {
            numberNode->IntConst = 0;
        }
    }
    return numberNode;
}
